//处理监控数据
// export function handleData({ data }: any, title: any) {
//   let xAxis = []
//   let name = []
//   let yAxis = []
//   for (let i = 0; i < data.length; i++) {
//     xAxis.indexOf(data[i].createdAt) > -1 ? '' : xAxis.unshift(data[i].createdAt)
//     name.indexOf(data[i].node_name) > -1 ? '' : name.push(data[i].node_name)
//   }
//   for (let i = 0; i < name.length; i++) {
//     yAxis.push({ name: name[i], data: [] as any })
//   }

//   for (let i = 0; i < data.length; i++) {
//     let page = i % name.length
//     if (title === 'SAMBA读带宽') {
//       yAxis[page].data.unshift(data[i].read_bytes)
//     }
//     if (title === 'SAMBA写带宽') {
//       yAxis[page].data.unshift(data[i].write_bytes)
//     }
//     if (title === '主机CPU使用率') {
//       yAxis[page].data.unshift(100 - data[i].idle)
//     }
//     if (title === '主机内存使用率') {
//       let memory_usage = data[i].used_bytes / data[i].total_bytes
//       yAxis[page].data.unshift(memory_usage)
//     }
//     if (title === '集群可用容量' || title === '集群容量' || title === '集群') {
//       yAxis[page].data.unshift(data[i].disk_size)
//     }
//     if (title === '网络接收带宽') {
//       let keymap: any = { rxkB: 'value' }
//       Object.keys(data[i]).map(k => {
//         let newKey: any = keymap[k]
//         if (newKey) {
//           data[i][newKey] = data[i][k]
//           delete data[i][k]
//         }
//       })
//       yAxis[page].data.unshift(data[i])
//     }
//     if (title === '网络发送带宽') {
//       let keymap: any = { txkB: 'value' }
//       Object.keys(data[i]).map(k => {
//         let newKey: any = keymap[k]
//         if (newKey) {
//           data[i][newKey] = data[i][k]
//           delete data[i][k]
//         }
//       })
//       yAxis[page].data.unshift(data[i])
//     }
//   }

//   return { yAxis, xAxis }
// }
// 改版 处理监控数据
export function handleData({ data }: any, title: any) {
  let xAxis = []
  let name = []
  let yAxis = []
  for (let i = 0; i < data.length; i++) {
    xAxis.indexOf(data[i].createdAt) > -1 ? '' : xAxis.unshift(data[i].createdAt)
    let temp = ''
    if(data[i].iface){
      temp = data[i].node_name+'-'+data[i].iface
    }else{
      temp = data[i].node_name
    }
    name.indexOf(temp) > -1 ? '' : name.push(temp)
  }
  for (let i = 0; i < name.length; i++) {
    yAxis.push({ name: name[i], data: [] as any })
  }

  for (let i = 0; i < data.length; i++) {
    let page = i % name.length
    if (title === 'SAMBA读带宽') {
      yAxis[page].data.unshift(data[i].read_bytes)
    }
    if (title === 'SAMBA写带宽') {
      yAxis[page].data.unshift(data[i].write_bytes)
    }
    if (title === '主机CPU使用率') {
      yAxis[page].data.unshift(100 - data[i].idle)
    }
    if (title === '主机内存使用率') {
      let memory_usage = data[i].used_bytes / data[i].total_bytes
      yAxis[page].data.unshift(memory_usage)
    }
    if (title === '集群可用容量' || title === '集群容量' || title === '集群') {
      yAxis[page].data.unshift(data[i].disk_size)
    }
    if (title === '网络接收带宽') {
      let keymap: any = { rxkB: 'value' }
      Object.keys(data[i]).map(k => {
        let newKey: any = keymap[k]
        if (newKey) {
          data[i][newKey] = data[i][k]
          delete data[i][k]
        }
      })
      yAxis[page].data.unshift(data[i])
    }
    if (title === '网络发送带宽') {
      let keymap: any = { txkB: 'value' }
      Object.keys(data[i]).map(k => {
        let newKey: any = keymap[k]
        if (newKey) {
          data[i][newKey] = data[i][k]
          delete data[i][k]
        }
      })
      yAxis[page].data.unshift(data[i])
    }
  }

  return { yAxis, xAxis }
}

//单位换算
export function unitConversion(bytes: any) {
  if (bytes == 0) return '0 KB'
  let k = 1024
  let sizes = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
  let i = Math.floor(Math.log(bytes) / Math.log(k))
  if (i === -1) {
    return (bytes / Math.pow(k, i)).toPrecision(3) + ' KB'
  } else {
    return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i]
  }
}
//时间转换
export function format(date: any) {
  date = new Date(date)
  let y = date.getFullYear()
  let m = date.getMonth() + 1
  let d = date.getDate()
  let h = date.getHours()
  let m1 = date.getMinutes()
  let s = date.getSeconds()
  m = m < 10 ? '0' + m : m
  d = d < 10 ? '0' + d : d
  h = h < 10 ? '0' + h : h
  m1 = m1 < 10 ? '0' + m1 : m1
  s = s < 10 ? '0' + s : s
  return y + '-' + m + '-' + d + ' ' + h + ':' + m1 + ':' + s
}
